﻿using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;

namespace ExtendedMvc.Elements {
	public class GridActionCommand<TModel> : GridCommandBase<GridActionCommand<TModel>, TModel>
		where TModel : class {
		private string _actionName;
		private string _controllerName;
		private RouteValueDictionary _routeValues;

		public GridActionCommand(IModelViewHelper<IEnumerable<TModel>> helper, string text, string actionName, string controllerName = null)
			: base(helper, text) {
			_actionName = actionName;
			_controllerName = controllerName;
		}

		public GridActionCommand<TModel> RouteValues(object routeValues) {
			_routeValues = routeValues is RouteValueDictionary ? routeValues as RouteValueDictionary : new RouteValueDictionary(routeValues);
			return this;
		}

		public override string GetLink() {
			return UrlHelper.GenerateUrl(null, _actionName, _controllerName, _routeValues, helper.RouteCollection, helper.ViewContext.RequestContext, true);
		}
	}
}
